package g11.actionutil;

import g11.dao.DAOException;
import g11.dao.EmployeeDAO;
import g11.dao.EmployeeDAOImpl;
import g11.model.Employee;
import g11.dao.WorkForDAO;
import g11.dao.WorkForDAOImpl;
import g11.model.Patient;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.TreeMap;


/**
 * @author Fern: complicate methods on Employee, Patient, the WorkFor and PatientAssingment relationship
 * 
 */
public class EntityRltnUtilImpl implements EntityRltnUtil {
	/**
	 * @param staffId
	 * Given the staffId, this function gets all the doctors this staff is working for
	 */
	public Map<String,String> getDoctorMapByStaffId(int staffId) throws DAOException{
		EmployeeDAOImpl eDao = new EmployeeDAOImpl();
		Employee staff = new Employee();
		try {
			staff = eDao.getEmployeeById(staffId);
		} catch (DAOException e1) {
			e1.printStackTrace();
		}
		WorkForDAO wDAO = new WorkForDAOImpl();
		List<Employee> retrievedDoctorList = new ArrayList<Employee>();
		try {
			retrievedDoctorList = wDAO.getDoctorList(staff);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Map<String, String> doctorMap = new TreeMap<String, String>();
		for(Employee e:retrievedDoctorList){
			doctorMap.put(String.valueOf(e.getId()), e.getName());
		}
		return doctorMap;
	}
	
	/**
	 * @param staffId
	 * Given the staffId, this function gets all the doctors this staff is working for;
	 * then finds all the patients belong to the doctors
	 */
	public Map<String, String> getPatientMapByStaffId (int staffId)throws DAOException{
		
		EmployeeDAOImpl eDao = new EmployeeDAOImpl();
		Employee staff = new Employee();
		try {
			staff = eDao.getEmployeeById(staffId);
		} catch (DAOException e1) {
			e1.printStackTrace();
		}
		
		PatientUtilImpl paui = new PatientUtilImpl();
		List<Patient> retrievedPatientList = new ArrayList<Patient>();
		try {
			retrievedPatientList = paui.getPatientByStaffBelongTo(staff);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		
		Map<String, String> patientMap = new TreeMap<String, String>();
		for(Patient e:retrievedPatientList){
			patientMap.put(String.valueOf(e.getId()), e.getName());
		}
		return patientMap;
	}


}
